//
//  MoreBankViewCell.swift
//  KaMengApplication
//
//  Created by DUONIU_MAC on 2018/11/28.
//  Copyright © 2018年 DUONIU_MAC. All rights reserved.
//

import UIKit

class MoreBankViewCell: UITableViewCell {
    
    var model : BankDetailsModel! {
        didSet{
            getData()
        }
    }
    
    fileprivate let nameLabel = UILabel() //标题
    fileprivate let distanceLabel = UILabel() //距离
    fileprivate let addressLabel = UILabel() //地区

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        nameLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.contentView.addSubview(nameLabel)
        
        distanceLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.contentView.addSubview(distanceLabel)
        
        addressLabel.font = UIFont.systemFont(ofSize: RATIO(maxNum: 16))
        self.contentView.addSubview(addressLabel)
        
        let linearView = UIView()
        linearView.backgroundColor = UIColor.black
        self.contentView.addSubview(linearView)
        
        let lineView = UIView()
        lineView.backgroundColor = UIColor.lineColor()
        self.contentView.addSubview(lineView)
        
        nameLabel.snp.makeConstraints { (make) in
            make.top.equalToSuperview().offset(RATIO_H(maxNum: 10))
            make.left.equalToSuperview().offset(RATIO(maxNum: 10))
            make.width.greaterThanOrEqualTo(10)
            make.height.equalTo(RATIO_H(maxNum: 25))
        }
        
        distanceLabel.snp.makeConstraints { (make) in
            make.left.height.equalTo(nameLabel)
            make.top.equalTo(nameLabel.snp.bottom)
            make.width.greaterThanOrEqualTo(10)
        }
        
        linearView.snp.makeConstraints { (make) in
        make.left.equalTo(distanceLabel.snp.right).offset(RATIO(maxNum: 5))
            make.centerY.equalTo(distanceLabel)
            make.height.equalTo(RATIO_H(maxNum: 20))
            make.width.equalTo(1)
        }
        
        addressLabel.snp.makeConstraints { (make) in
        make.left.equalTo(linearView.snp.right).offset(RATIO(maxNum: 5))
            make.centerY.height.equalTo(distanceLabel)
            make.width.greaterThanOrEqualTo(10)
        }
        
        lineView.snp.makeConstraints { (make) in
            make.left.right.bottom.equalToSuperview()
            make.height.equalTo(1)
        }
    }
    
    //MARK: 更新数据
    fileprivate func getData() {
        
        nameLabel.text = model.name
        addressLabel.text = model.address
        
        if model.distance! > 1000 {
            let km = "\(Double(model.distance!)/1000)"
            distanceLabel.text = String(format: "%.1f", Double(km) ?? 0) + "km"
        }else{
            distanceLabel.text = "\(model.distance!)" + "m"
        }
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    

}
